package br.com.j7.jdesk.persistence.repository.impl;

import java.util.List;

import br.com.j7.jdesk.library.exception.RepositoryException;
import br.com.j7.jdesk.persistence.entity.Enterprises;
import br.com.j7.jdesk.persistence.entity.Products;
import br.com.j7.jdesk.persistence.repository.ProductRepository;

/**
 * Class Repositorio da entidade Products
 * 
 * @author Edivando Alves
 *
 */
public class ProductRepositoryImpl extends AbstractRepository<Products> implements ProductRepository{


	/*
	 * (non-Javadoc)
	 * @see br.com.j7.jdesk.persistence.repository.impl.AbstractRepository#list()
	 */
	@Override
	public List<Products> list() throws RepositoryException {
		try {
			return listByNamedQuery(Products.class, "list");
		} catch (RepositoryException e) {
			throw new RepositoryException(e);
		}
	}
	
	/*
	 * (non-Javadoc)
	 * @see br.com.j7.jdesk.persistence.repository.ProductRepository#listByEnterprise(br.com.j7.jdesk.persistence.entity.Enterprises)
	 */
	public List<Products> listByEnterprise(Enterprises enterprise) throws RepositoryException{
		try {
			return listByNamedQuery(Products.class, "productByEnterprise", enterprise);
		} catch (RepositoryException e) {
			throw new RepositoryException(e);
		}
	}

	/*
	 * (non-Javadoc)
	 * @see br.com.j7.jdesk.persistence.repository.impl.AbstractRepository#find(java.lang.Integer)
	 */
	@Override
	public Products find(Integer id) throws RepositoryException {
		try {
			return getEntity(Products.class, id);
		} catch (RepositoryException e) {
			throw new RepositoryException(e);
		}
	}
	
	/*
	 * (non-Javadoc)
	 * @see br.com.j7.jdesk.persistence.repository.ProductRepository#findByCode(java.lang.String, br.com.j7.jdesk.persistence.entity.Enterprises)
	 */
	@Override
	public Products findByCode(String cdCode, Enterprises enterprise) throws RepositoryException{
		try {
			return getEntity(Products.class, "productByCdCodeAndEnterprise", cdCode, enterprise);
		} catch (RepositoryException e) {
			throw new RepositoryException(e);
		}
	}

}
